home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / gle / s.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-29  |  7.9 KB  |  535 lines

  1. #define unix true
  2. #include <stdio.h>
  3. #ifdef ultrix
  4. #include <cursesX.h>
  5. #else
  6. #include <cur00.h>
  7. #include <cur01.h>
  8. #include <cur02.h>
  9. #include <cur03.h>
  10. #endif
  11. #include <signal.h>
  12. #include "vaxconio.h"
  13. #define false 0
  14. #define true (!false)
  15. #define dbg if (1==1)
  16. int iserr;
  17. int dont_clear;
  18. int noscreenio;
  19. main()
  20. {
  21.   scr_init();
  22.   scr_refresh();
  23.   printw("Hello\n");
  24.   scr_inv();
  25.   printw("world\n");
  26.   for (;;) {
  27.     printw("%d\n",getch());
  28.     scr_refresh();
  29.   }
  30.   scr_end();
  31. }
  32.  
  33. delay(int i)
  34. {}
  35. int vx_top=1,vx_bot=24;
  36. textattr()
  37. {}
  38. abort_key()
  39. {
  40.     return false;
  41. }
  42. kbhit()
  43. {
  44.     return false;
  45. }
  46. scr_gets(char *x)
  47. {
  48.     getstr(x);
  49. }
  50. clreol()
  51. {
  52.     if (noscreenio) return;
  53.     clrtoeol();
  54. }
  55. cputs(char *line)
  56. {
  57.     int x;
  58.     int y;
  59.     if (noscreenio) return;
  60.     getyx(stdscr,y,x);
  61.     mvaddstr(y,x,line);
  62. }
  63. delline()
  64. {
  65.     int x;
  66.     int y;
  67.     getyx(stdscr,y,x);
  68.     move(22,1);
  69.     clrtobot();
  70.     move(y,1);
  71.     deleteln();
  72.     move(y,x);
  73. }
  74. gotoxy(int x, int y)
  75. {
  76.     if (noscreenio) return;
  77.     if (y==25) y=24;
  78.     move(y+vx_top-2,x);
  79. }
  80. insline()
  81. {
  82.     int x;
  83.     int y;
  84.     getyx(stdscr,y,x);
  85.     move(y,x);
  86.     insertln();
  87.     move(y,x);
  88.     move(22,1);
  89.     clrtobot();
  90.     move(y,x);
  91.  
  92. }
  93. putch(int char_val)
  94. {
  95.     int x;
  96.     int y;
  97.     getyx(stdscr,y,x);
  98.     mvaddch(y,x,char_val);
  99. }
  100. int scr_refresh()
  101. {
  102.     if (!noscreenio) refresh();
  103.     else {printf("not refreshing, \n"); refresh();}
  104. }
  105. int scr_getch()
  106. {
  107.     if (noscreenio) return getc(stdin);
  108.     else return getch();
  109. }
  110. trap(int sig)
  111. {
  112.     echo();
  113.     nl();
  114.     nocbreak();
  115.     endwin();
  116.     exit(sig);
  117. }
  118. scr_init()
  119. {
  120.     static int doneinit;
  121. #ifdef ultrix
  122.     signal(SIGINT,trap);
  123. #endif
  124.     if (doneinit) {printf("init called twice \n"); exit();}
  125.     doneinit = true;
  126.     initscr();
  127.     scrollok(stdscr,true);
  128.  
  129. #ifdef unix
  130.     noecho();
  131.     nonl();
  132.     cbreak();
  133.     clear();
  134.     keypad(stdscr,TRUE);
  135. #endif
  136. }
  137. scr_end()
  138. {
  139.     if (noscreenio) return;
  140.     echo();
  141.     nl();
  142.     nocbreak();
  143.     endwin();
  144. }
  145. textbackground(int color_num)
  146. {}
  147. textcolor(int colornum)
  148. {}
  149. gettextinfo(struct text_info *r)
  150. {
  151.     int x;
  152.     int y;
  153.     if (noscreenio) return;
  154.     getyx(stdscr,y,x);
  155.     r->curx = x;
  156.     r->cury = y;
  157.     r->wintop = vx_top;
  158. }
  159. screen_save()
  160. {}
  161. screen_restore()
  162. {
  163.     if (noscreenio) return;
  164.     scr_norm();
  165.     clrscr();
  166.     gotoxy(1,1);
  167.     cputs("\n");
  168. }
  169. int wyerr;
  170. w_message(char *s)
  171. {
  172.     wyerr++;
  173.     if (noscreenio) return;
  174.     scr_savexy();
  175.     gotoxy(1,wyerr);
  176.     clreol();
  177.     cputs(s);
  178.     scr_restorexy();
  179. }
  180. window(int left,int top, int right, int bottom)
  181. {
  182.     if (left==1 && top==1 && bottom==25) {
  183.     if (noscreenio) return;
  184. #ifndef unix
  185.         printf("\x1b[%d;%dr",1,24);
  186. #endif
  187.     }
  188.     vx_top = top;
  189.     vx_bot = bottom;
  190.     wyerr = 0;
  191. }
  192. clrscr()
  193. {
  194.     if (noscreenio) return;
  195.     if (vx_top==1 && vx_bot==25) {
  196.         clearok(stdscr,TRUE);
  197.         clear();
  198.         refresh();
  199.         clearok(stdscr,FALSE);
  200.         return;
  201.     }
  202.     clear();
  203. }
  204. scr_dots(int i)
  205. {
  206. }
  207. scr_left(int i)
  208. {
  209.     int y,x;
  210.     if (i<=0) return;
  211.     getyx(stdscr,y,x);
  212.     move(y,x-i);
  213. }
  214. scr_right(int i)
  215. {
  216.     int y,x;
  217.     if (i<=0) return;
  218.     getyx(stdscr,y,x);
  219.     move(y,x+i);
  220. }
  221. int vx_topsave,vx_botsave;
  222. int savex,savey;
  223. scr_savexy()
  224. {
  225.     if (noscreenio) return;
  226.     getyx(stdscr,savey,savex);
  227.     vx_topsave = vx_top;
  228.     vx_botsave = vx_bot;
  229.  
  230. }
  231. scr_restorexy()
  232. {
  233.     if (noscreenio) return;
  234.     move(savey,savex);
  235.     vx_top = vx_topsave;
  236.     vx_bot = vx_botsave;
  237. }
  238.  
  239. scr_norm()  /* yellow on blue */
  240. {
  241. /*    attrset(A_NORMAL);*/
  242. }
  243. scr_inv()   /* black on white */
  244. {
  245. /*    attrset(A_BOLD);*/
  246. }
  247. scr_grey()  /* black on grey */
  248. {
  249. /*    attrset(A_REVERSE);*/
  250. }
  251. scr_isblackwhite()
  252. {
  253.     return true;
  254. }
  255. scr_menubg()
  256. {
  257.     scr_norm();
  258. }
  259. scr_menuval()
  260. {
  261.     scr_inv();
  262. }
  263. scr_menuhi()
  264. {
  265.  
  266.     scr_grey();
  267. }
  268.  
  269. #ifndef unix
  270. #include <descrip.h>
  271. vax_edt(char *s)     /* call the vax EDT editor */
  272. {
  273.     $DESCRIPTOR(sdesc,"");
  274.     sdesc.dsc$a_pointer = s;
  275.     sdesc.dsc$w_length = strlen(s);
  276.     edt$edit(&sdesc,&sdesc);
  277. }
  278. #else
  279. vax_edt(char *s)
  280. {}
  281. #endif
  282.  
  283. #include "edt.h"
  284. #define true (!false)
  285. #define false 0
  286. int fner(char *s);
  287. int scr_refresh(void);
  288. int scr_getch(void);
  289. char *function_bar()
  290. {
  291.     return "F11-Help F12-Save F13-Load F14-Saveas F9-Graphmenu F10-Drawit ^x=Exit";
  292. }
  293.  
  294. struct escape_struct {char *str; int val;};
  295.  
  296. struct escape_struct gold[] = {
  297.         "v",     epaste,
  298.         "R",    esearch,
  299.         "S",    eundeleol,
  300.         NULL,    };
  301.  
  302. struct escape_struct eseq[] = {
  303.         "4~",     eselect,
  304.         "1~",    esearch,
  305.         "2~",    epaste,
  306.         "3~",    ecut,
  307.         "4~",    eselect,
  308.         "5~",    epageup,
  309.         "6~",    epagedown,
  310.         "A",    eup,
  311.         "B",    edown,
  312.         "C",    eright,
  313.         "D",    eleft,
  314.         "20~",    egraphmenu,
  315.         "21~",    edrawit,
  316.         "23~",    ehelp,
  317.         "24~",    esave,
  318.         "25~",    eload,
  319.         "26~",    esaveas,
  320.         "P",    egold,
  321.         "Q",    ehelp,
  322.         "R",    efindnext,
  323.         "S",    edeleol,
  324.         "n",    eselect,
  325.         "v",    ecut,
  326.         "l",    edelright,
  327.         NULL,    };
  328.  
  329. int gold_fn[] = {
  330.     edrawit,ehelp,esave,eload,esaveas,eshowerror,0,0,0,egraphmenu,edrawit
  331. };
  332. struct keymatch {int m; int val;};
  333. /* Normal key and ^ commands  commands */
  334. struct keymatch kmatch2[] = {
  335.     13, ereturn,
  336.     3, equit,
  337.     4, eword,
  338.     5, eedt,
  339.     6, efast,
  340.     7, edrawit,
  341.     18, eshowerror,
  342.     8, ehelp,
  343.     20, etrace,
  344.     12, efindnext,
  345.     21, eundelline,
  346.     24, eescape,
  347.     25, edelline,
  348.     26, eescape,
  349.     27, eescape,
  350.     127, edelete,
  351.     0,0
  352. };
  353. struct keymatch kmatchx[] = {
  354.     KEY_DOWN, edown,
  355.     KEY_UP, eup,
  356.     KEY_F0+4, edeleol,
  357.     KEY_LEFT, eleft,
  358.     KEY_RIGHT, eright,
  359.     KEY_NPAGE, epagedown,
  360.     KEY_PPAGE, epageup,
  361.     0,0
  362. };
  363. /* Control K commands */
  364. struct keymatch kmatch3[] = {
  365.     'b', eselect,
  366.     'v', emove,
  367.     'k', emark,
  368.     'c', ecopy,
  369.     'y', ecut,
  370.     'u', epaste,
  371.     'p', epaste,
  372.     'r', eblockread,
  373.     'w', eblockwrite,
  374.     'm', egraphmenu,
  375.     'l', eload,
  376.     'd', edrawit,
  377.     's', esave,
  378.     'x', equit,
  379.     0,0
  380. };
  381. /* Control Q commands */
  382. struct keymatch kmatch4[] = {
  383.     'f', esearch,
  384.     'c', eendoffile,
  385.     'r', etopoffile,
  386.     0,0
  387. };
  388. extern int noscreenio;
  389. tt_inkey()
  390. {
  391.     int i;
  392.     if (noscreenio) return getc(stdin);
  393.     else {
  394.         i = getch();
  395.             printf(" <(%d)> ",i);
  396.         return i;
  397.     }
  398. }
  399. text_inkey()
  400. {
  401.     int cc,i,c1,c2;
  402.  
  403.     scr_refresh();
  404.  
  405. loop1:    cc = tt_inkey();
  406.     c2 = cc;
  407.     if (c2==KEY_F(1)) return do_gold();
  408.     if (cc>KEY_BREAK) {
  409.         for (i=0;kmatchx[i].m!=0;i++)
  410.         if (kmatchx[i].m==c2) return kmatchx[i].val;
  411.     }
  412.     switch(c2) {
  413.       default:
  414.         for (i=0;kmatch2[i].m!=0;i++)
  415.         if (kmatch2[i].m==c2) return kmatch2[i].val;
  416.         break;
  417.       case 27:
  418.         c2 = tt_inkey(); /* throw away next char (unless escape) */
  419.         if (c2==27) return eescape;
  420.       case -101:
  421.       case -113:
  422.         c2 = escape_seq();
  423.         if (c2==egold)     return do_gold();
  424.         return c2;
  425.         break;
  426.       case 17:
  427.         fner("^Q  F=Find string,  R=Top of file");
  428.         cc = tt_inkey();
  429.         c2 = (cc & 0xff);
  430.         if (c2<32) c2 = c2 + 'a' - 1;
  431.         c2 = tolower(c2);
  432.         for (i=0;kmatch4[i].m!=0;i++)
  433.         if (kmatch4[i].m==c2) return kmatch4[i].val;
  434.         fner("Unrecognized Quick movement command");
  435.         goto loop1;
  436.       case 11:
  437.         fner("^K  B=begin block,  P=Paste,  (use KP6 for Cut),  K=End block");
  438.         cc = tt_inkey();
  439.         c2 = (cc & 0xff);
  440.         if (c2<32) c2 = c2 + 'a' - 1;
  441.         c2 = tolower(c2);
  442.         for (i=0;kmatch3[i].m!=0;i++)
  443.         if (kmatch3[i].m==c2) return kmatch3[i].val;
  444.         fner("Unrecognized block command");
  445.         goto loop1;
  446.     }
  447.     return c2;
  448. }
  449. escape_seq()
  450. {
  451.     int cc,i;
  452.     unsigned char esq[10];
  453.     char *s;
  454.  
  455.     s = &esq[0];
  456.     *s++ = cc = tt_inkey();
  457.     while (cc<65) *s++ = cc = tt_inkey();
  458.     *s++ = 0;
  459.     for (i=0;eseq[i].str!=NULL;i++)
  460.         if (strcmp(eseq[i].str,esq)==0) break;
  461.     if (eseq[i].str!=NULL)
  462.         return eseq[i].val;
  463.     else
  464.         return 0;
  465.  
  466. }
  467. escape_seq_gold()
  468. {
  469.     int cc,i;
  470.     unsigned char esq[10];
  471.     char *s;
  472.  
  473.     s = &esq[0];
  474.     *s++ = cc = tt_inkey();
  475.     while (cc<65) *s++ = cc = tt_inkey();
  476.     *s++ = 0;
  477.     for (i=0;gold[i].str!=NULL;i++)
  478.         if (strcmp(gold[i].str,esq)==0) break;
  479.     if (gold[i].str!=NULL)
  480.         return gold[i].val;
  481.     else
  482.         return 0;
  483.  
  484. }
  485.  
  486. do_gold()
  487. {
  488.     int c2;
  489.     c2 = tt_inkey();
  490.     if (c2==KEY_F(4)) return eundeleol;
  491.     if (c2==27) {
  492.         tt_inkey();
  493.         return escape_seq_gold();
  494.     } else if (isdigit(c2)) {
  495.         return gold_fn[c2-'0'];
  496.     }
  497. }
  498.  
  499. char *function_bar(void);
  500. fner_clear()
  501. {
  502.     if (noscreenio) return;
  503.     if (iserr==false) return;
  504.     if (dont_clear) return;
  505.     window(1,1,80,25);
  506.     gotoxy(1,25);
  507.     scr_grey();
  508.     clreol();
  509.     gotoxy(2,25);
  510.     cputs(function_bar());
  511.     scr_norm();
  512.     iserr = false;
  513.     window(2,3,79,23);
  514. }
  515. extern int noscreenio;
  516. fner(char *s)
  517. {
  518.     if (dont_clear) return;
  519.     if (noscreenio) {
  520.         printf("%s\n",s);
  521.         return;
  522.     }
  523.     scr_savexy();
  524.     iserr = true;
  525.     window(1,1,80,25);
  526.     gotoxy(1,25);
  527.     scr_inv();
  528.     clreol();
  529.     gotoxy(2,25);
  530.     cputs(s);
  531.     scr_norm();
  532.     scr_restorexy();
  533.     scr_refresh();
  534. }
  535.